#ifndef __ILI9341_DRV_H
#define __ILI9341_DRV_H

#include "_config_cpu_.h"
#include "_config_cpu_spi.h"

#if (ILI9341_USE_SPI == 1)
	#if defined(cortexm3)
	#include "ssp1.h"
	#define ili9341_TransferByte(c)	ssp1_TransferByte(c)
	#else
	#include "spi1.h"
	#define ili9341_TransferByte(c)	spi1_TransferByte(c)
	#endif

#elif (ILI9341_USE_SPI == 0)
	#if defined(cortexm3)
	#include "ssp0.h"
	#define ili9341_TransferByte(c)	ssp0_TransferByte(c)
	#else
	#include "spi0.h"
	#define ili9341_TransferByte(c)	spi0_TransferByte(c)
	#endif
#else
	#error NÃO FOI DEFINIDO A PORTA SPI PARA O ILI9341 EM _config_cpu_spi.h
#endif

// FUNCTIONS
#if (ILI9341_USE_RESET == pdON)
#define ili9341_SetupPorts()	{ ILI9341_CS_DIR |= ILI9341_CS; ILI9341_CMD_DIR |= ILI9341_CMD; ILI9341_RST_DIR |= ILI9341_RST;}
#define ili9341_ResetOn()		(ILI9341_RST_CLR = ILI9341_RST)
#define ili9341_ResetOff()		(ILI9341_RST_SET = ILI9341_RST)
#else
#define ili9341_SetupPorts()	{ ILI9341_CS_DIR |= ILI9341_CS; ILI9341_CMD_DIR |= ILI9341_CMD;}
#endif

#define ili9341_Enable() 		ILI9341_CS_CLR =  ILI9341_CS 			// CS = 0 ativar o driver
#define ili9341_Disable()  		ILI9341_CS_SET =  ILI9341_CS 			// CS = 1 desativar o driver
#define ili9341_Command()  		ILI9341_CMD_CLR =  ILI9341_CMD
#define ili9341_Data()  		ILI9341_CMD_SET =  ILI9341_CMD

#endif
